
package com.kweative.model.test.model;

import com.kweative.model.Entity;
import com.kweative.model.Index;
import com.kweative.model.apt.annotation.TableDeclaration;
import com.kweative.model.exception.StructureException;
import com.kweative.model.column.ColumnEmail;
import com.kweative.model.column.ColumnEnum;
import com.kweative.model.column.ColumnPassword;
import com.kweative.model.column.ColumnText;

/**
 *
 * @author henrik
 */
@TableDeclaration
public class User extends Entity<UserRow,User,BasicSchema> {
    public ColumnEmail<User> Email;
    public ColumnPassword<User> Password;
    public ColumnText<User> Firstname;
    public ColumnText<User> Lastname;
    public ColumnEnum<User> Type;

    public Index UserPass;

    @Override
    protected void makeStructure() throws StructureException {
        UserPass = addIndex(new Index(Index.Type.UNIQUE));
        Type = addColumn(new ColumnEnum(UserType.class));
        Email = addColumn(new ColumnEmail<User>(), UserPass);
        Password = addColumn(new ColumnPassword<User>(), UserPass);
        Firstname = addColumn(new ColumnText<User>(ColumnText.Size.NAME));
        Lastname = addColumn(new ColumnText<User>(ColumnText.Size.NAME));
    }

    /* STATEMENT WRAPPERS */

    public boolean authorize(String email,String password) {
        return select().using(UserPass,email,password).exists();
    }
    
    public enum UserType {
        ADMIN,
        GUEST,
        USER
    }

}
